package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.SysDictType;
import com.hee.erp.modules.entity.SysDictValue;
import com.hee.erp.modules.mapper.SysDictValueMapper;
import com.hee.erp.modules.service.ISysDictTypeService;
import com.hee.erp.modules.service.ISysDictValueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-03-21
 */
@Service
@Transactional
public class SysDictValueServiceImpl extends ServiceImpl<SysDictValueMapper, SysDictValue> implements ISysDictValueService {

    @Autowired
    ISysDictTypeService sysDictTypeService;

    @Override
    public List<SysDictValue> getListByTypeValue(String dictTypeValue) {

        LambdaQueryWrapper<SysDictType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysDictType::getTypeValue,dictTypeValue);
        SysDictType one = sysDictTypeService.getOne(queryWrapper);

        LambdaQueryWrapper<SysDictValue> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(SysDictValue::getDictTypeId,one.getId());
        List<SysDictValue> list = this.list(queryWrapper1);

        return list;
    }

    @Override
    public SysDictValue getByTypeAndValue(String dictType, Integer value) {
        SysDictType dictTypeEntity = sysDictTypeService.getByType(dictType);
        if(dictTypeEntity != null){
            LambdaQueryWrapper<SysDictValue> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysDictValue::getDictTypeId,dictTypeEntity.getId());
            queryWrapper.eq(SysDictValue::getDictValue ,value);
            SysDictValue one = this.getOne(queryWrapper);
            return one;
        }
        return null;
    }
}
